package ThreadSecurity;

import org.omg.PortableServer.THREAD_POLICY_ID;

public class SaleThread implements Runnable{

    private int tickets = 10;

    @Override
    public void run() {

        while(true){
            if(tickets > 0){
                try{
                    Thread.sleep(100);
                }catch(Exception e){
                    e.printStackTrace();
                }
                System.out.println(Thread.currentThread().getName() + "窗口正在出售第"+tickets--+"张票~");
            }
        }

    }

    public static void main(String[] args) {

        SaleThread s = new SaleThread();
        // 创建线程
        Thread thread1 = new Thread(s,"窗口1");
        Thread thread2 = new Thread(s,"窗口2");
        Thread thread3 = new Thread(s,"窗口3");
        Thread thread4 = new Thread(s,"窗口4");

        thread1.start();
        thread2.start();
        thread3.start();
        thread4.start();

    }

}
